﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ServiceModel;
using USTF.Media.MediaService;
using System.ServiceModel.Channels;

namespace USTF.Media.MediaServiceConsumer
{
    public class AuthenticatedUSTFClient : USTFMediaServiceProxy.USTFMediaServiceClient
    {
        protected override USTFMediaServiceProxy.IUSTFMediaService CreateChannel()
        {
            
            return base.CreateChannel();
        }
    }

    public static class Transport
    {
        public static USTFMediaServiceProxy.USTFMediaServiceClient GetClient(string username, string password, string serviceUrl)
        {
            //set basic http binding with high transfer-size limits
            var binding = new ClientChannelBinding() { Username = username, Password = password };
           
            //setting the credentials on the binding doesn't get passed thru to the client, so
            //we're temporarily being creative here
            TemporaryCredentialStore.Current.Username = username;
            TemporaryCredentialStore.Current.Password = password;

            //new service proxy
            var result = new USTFMediaServiceProxy.USTFMediaServiceClient(
                binding,
                new EndpointAddress(serviceUrl)
                );
            
            //result.ChannelFactory.Endpoint.Behaviors.Add


            //NOTE: this doesn't work in silverlight over HTTP!
            ////credentials
            //if (!String.IsNullOrEmpty(username))
            //{
            //    result.ClientCredentials.UserName.UserName = username;
            //    result.ClientCredentials.UserName.Password = password;
            //}

            return result;
        }

    }
}
